<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <meta name="viewport"
        content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, user-scalable=no" />
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/ui-res.css">
        <link rel="stylesheet" href="css/ui-btn.css">
        <link rel="stylesheet" href="css/index.css">
        <!-- <script src="js/zy_control.js"></script>
        <script src="js/zy_click.js"></script> -->
        <script type="text/javascript">
            window.uexOnload = function() {
                uexDownloaderMgr.onStatus = downloadStatus;
                uexDownloaderMgr.cbCreateDownloader = createDownloader;
                uexDownloaderMgr.cbGetInfo = getDownloadFileInfo;
            }
            
            var id = 1;

            function download() {
                //1. 创建下载对象，会回调cbCreateDownload方法
                uexDownloaderMgr.createDownloader(id);
            }

            // 4.监听下载的结果
            function downloadStatus(id, fileSize, percent, status) {
                switch (status) {
                case 0:
                    document.getElementById('percentage').innerHTML = "文件大小：" + fileSize + "字节<br>下载进度：" + percent;
                    break;
                case 1:
                    alert("下载完成");
                    // 关闭下载~
                    uexDownloaderMgr.closeDownloader(id);
                    break;
                case 2:
                    alert("下载失败");
                    uexDownloaderMgr.closeDownloader(id);
                    break;
                case 3:
                    alert("已取消下载");
                    break;
                }
            }

            // 2.创建下载对象之后会回调该方法
            // id：下载对象的唯一标识符
            // dataType：数据类型
            // data：回调的int型的数据，0-成功，1-失败
            function createDownloader(id, dataType, data) {
                var cText = 0;
                var cJson = 1;
                var cInt = 2;

                switch(dataType) {
                case cText:
                    alert("uex.cText");
                    break;
                case cJson:
                    alert("uex.cJson");
                    break;
                case cInt:
                    if (data == 0) {
                        alert("创建成功");
                        // 3.download 下载文件，使用onStatus监听
                        // id：用户自定义的下载对象唯一标识符
                        // serverURL：服务器地址
                        // savePath:本地保存地址
                        // mode:是否支持断点续传，0:不支持，1:支持
                        uexDownloaderMgr.download(id, serverURL, savePath, '0');
                    } else {
                        alert("创建失败");
                    }
                    break;
                default:
                    alert("error");
                }
            }

            // 获取下载信息回调函数
            function getDownloadFileInfo(id, dataType, data) {
                switch(dataType) {
                case cText:
                    alert("uex.cText");
                    break;
                case cJson:
                    if (data == null || data.length == 0) {
                        alert("无数据");
                        return;
                    }
                    alert(data);
                    var info = eval('(' + data + ')');
                    document.getElementById('fileInfo').innerHTML = "文件路径：" + info.savePath + "<br>文件大小：" + info.fileSize + "<br>已下载：" + info.currentSize + "<br>下载时间：" + info.lastTime;
                    break;
                case cInt:
                    alert("uex.cInt");
                    break;
                default:
                    alert("error");
                }
            }

            // 结束下载
            function closeDownload() {
                uexDownloaderMgr.closeDownloader(id);
            }

        </script>
    </head>
    <body class="um-vp " ontouchstart>
        <div class="conbor">
            <div class="consj">
                <span>下载地址：</span>
                <input class="textbox" id="downloadPath" type="text" value="http://221.7.204.182:8016/ovm/Uploads/course_pdf/test.pdf" >
                <span>保存地址：</span>
                <input class="textbox" id="savedPath" type="text" value="wgt://wgtRes//pdf//ovm.pdf" >
                <input  class="btn" type="button" value="下载文件" onclick="download();">
                <span>文件下载状态</span>
                <div class="tcxx" id="percentage"></div>
                <span>结束下载</span>
                <input  class="btn" type="button" value="结束下载" onclick="closeDownload();">
                <br>
            </div>
        </div>
    </body>
    <script></script>
</html>
